<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>${projectName}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src='<c:url value="/js/boot.js"></c:url>'></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>' />
<style type="text/css">
body, html {
	width: 100%;
	height: 100%;
	margin: 0;
	font-family: "微软雅黑";
}

#detailPan {
	width: 100%;
	height: 100%;
}

p {
	margin-left: 5px;
	font-size: 14px;
}

body {
	height: 100%;
	overflow: hidden;
}

.filterPan td {
	padding: 0;
}

.level1Class {
	margin-left: 10px;
}

.level2Class {
	margin-left: 30px;
}

.level3Class {
	margin-left: 50px;
}

.green {
	background-color: #E0FFD0;
}

.red {
	background-color: #FFEBE6;
	color: red;
}

.mini-splitter-pane {
	overflow: auto;
}

.mini-panel-body {
	padding: 0;
}

html body .searchbox .mini-buttonedit-icon {
	background: url('<c:url value="/share/img/magnifier-zoom.png"></c:url>')
		no-repeat 5% 5%;
}

.nameTitle {
	color: red;
}
</style>
<script type="text/javascript">
	
</script>

</head>
<body>
	<div class="mini-toolbar"
		style="padding: 0px; border-width: 1px; border-bottom-width: 0px;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 5px; height: 23px;"></td>
				<td><a class="mini-button" id="updateBtn" iconCls="icon-edit"
					plain="true" onclick="edit">修改</a><a class="mini-button"
					id="useBtn" iconCls="icon-check" plain="true" onclick="use(1)">启用</a><a
					class="mini-button" id="deleteBtn" iconCls="icon-cancel" plain="true"
					onclick="use(0)">禁用</a></td>
			</tr>
		</table>
	</div>
	<div class="mini-fit">
		<div id="datagrid1" class="mini-datagrid gridFull"
			borderStyle="border:1;" showReloadButton="true" pagesize="100"
			sizeList="[20,50,100,200]" allowCellWrap="true"
			allowHeaderWrap="true" idField="No" multiSelect="false"
			showPager="false" allowAlternating="true"
			ondrawcell="ondatagridDrawCell" onrowdblclick="dbClick"
			style="height: 100%; width: 100%; -moz-user-select: none; -webkit-user-select: none;"
			collapseGroupOnLoad="false" showColumnsMenu="true"
			showFilterRow="false" onshowrowdetail="onShowRowDetail">
			<div property="columns">
				<div type="indexcolumn" width="40px"></div>
				<div type="checkcolumn" width="40px" align="center"></div>
				<!-- <div field="Action" width="70px" headerAlign="center" align="center">
				</div> -->
				<div field="MailUser" width="200px" headerAlign="center"
					align="center" allowSort="true">邮箱账号</div>
				<div field="Content" width="200px" headerAlign="center"
					align="left" allowSort="true">邮件标题</div>
				<div field="EmailType" width="100px" headerAlign="center"
					align="left" allowSort="true">发邮类型</div>
				<div field="Receive" width="400px" headerAlign="center"
					align="left" allowSort="true">指定接收人</div>
				<div name="emptyCol" width='100%' headerAlign="center"
					align="center" cellStyle="padding:0;"></div>
			</div>
		</div>
	</div>

	<script type="text/javascript">
		mini.parse();
		mini_debugger = false;
		var isKeepStat3 = false;

		var rootPath = '${rootPath}';

		var datagrid1 = mini.get("datagrid1");

		$(function() {
			loadGrid1();
		});
		function loadGrid1() {
			var url = "<c:url value='/email/list' />";
			datagrid1.load(url);
			datagrid1.load();
		}
		function ondatagridDrawCell(e) {
			var row = e.row;
			var field = e.field;
			var valid = row.Valid;
			if(valid == 1 || valid == '1'){
				e.cellCls = 'green';
			}else{
				e.cellCls = 'red';
			}
			/* if (field == "Action") {
				var id = row.Id;
				e.cellHtml = '<a class="aTagUnderLine" href="javascript:update('
						+ id + ')">[查看]</a>';
			} */
		}
		function reloadList() {
			datagrid1.reload();
		}
		function dbClick(e) {
			var row = e.row;
			if (row) {
				update(row.Id);
			}
		}
		function use(type) {
			var title = null;
			if(type==1){
				title = '启用';
			}else{
				title = '禁用';
			}
			var row = datagrid1.getSelected();
			if(!row){
				mini.alert('请选择！');
				return;
			}
			var id= row.Id;
			if(!id){
				mini.alert('所选数据有误！');
				return;
			}
			mini.confirm("确定"+title+"？", "确定？", function(action) {
				if (action == "ok") {
					var url = rootPath + "/email/change/"+id+"/"+type;
					$.ajax({
						url : url,
						method : "post",
						dataType : "json",
						data : {
						},
						success : function(data) {
							if (data) {
								top.commonTools.showTip("操作成功！", 1);
								reloadList();
							} else {
								top.commonTools.showTip("操作失败！", 2);
								reloadList();
							}
						},
						error : function() {
							top.commonTools.showTip("操作发生错误！", 2);
						}

					});
				}
			});
		}
		
		
		
		function edit() {
			var row = datagrid1.getSelected();
			if(!row){
				mini.alert('请选择要修改的记录！');
				return;
			}
			update(row.Id);
		}	
		function update(id) {
			var url = "<c:url value='/email/update/' />"+id;
			mini.open({
				url : url,
				title : "修改邮件设置",
				width : 620,
				height : 540,
				onload : function() {
				},
				ondestroy : function(action) {
					if(action == 'ok'){
						reloadList();
					}
				}
			});
		}
	</script>
</body>
</html>